package org.apache.servicecomb.samples.practise.houserush.login.api;

import io.protostuff.Request;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.apache.servicecomb.samples.practise.houserush.login.entity.User;
import org.apache.servicecomb.samples.practise.houserush.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestSchema(schemaId = "userApi")
@RequestMapping("/")
public class UserApiImpl implements UserApi {
    @Autowired
    private UserService userService;
    @Override
    @PostMapping("users")
    public User createUser(@RequestBody User user) {
      /*  String token = request.getHeader("Authorization");
        int id = user.verifyTokenGetUserId(token);*/
        return userService.createUser(user);
    }

    @Override
    @GetMapping("users/{id}")
    public User findUser(@PathVariable("id") int id) {

        return userService.findUser(id);
    }

    @Override
    @DeleteMapping("users/{id}")
    public void removeUser(@PathVariable("id") int id) {
        userService.removeUser(id);

    }

    @Override
    @PutMapping("users/password")
    public boolean updatePassword(@RequestHeader int custumerId,@RequestBody User user) {
        return userService.updatePassword(custumerId,user.getOldPassword(),user.getPassword());
    }

    @Override
    @PutMapping("users/signin")
    public User signin(@RequestBody User user) {

        return userService.signin(user);
    }

    @Override
    @PutMapping("users/verify_token")
    public User verifyToken(String token) {
        return userService.verifyToken(token);
    }
}
